#include "tcpsocket.hpp"

//1. 创建套接字
//2. 绑定地址信息
//3. 向服务器发起连接请求
//while(1)
//    4. 发送数据
//    5. 接收数据
//6. 关闭套接字


int main(int argc, char *argv[])
{
    if(argc != 3){
        printf("em : ./tcp_cli srv_ip srv_port\n");
        return -1;
    }
    string ip = argv[1];
    uint16_t port = atoi(argv[2]);

    TcpSocket cli_sock;
    CHECK_RET(cli_sock.Socket());
    CHECK_RET(cli_sock.Connect(ip, port));
    while(1)
    {
        cout << "client say: " ;
        //fflush(stdout);
        string buf;
        cin >> buf;
        CHECK_RET(cli_sock.Send(buf));
        buf.clear();
        CHECK_RET(cli_sock.Recv(&buf));
        cout << "srver say: " << buf << endl;

    }
    cli_sock.Close();
    return 0;
}
